<template>
    <div class="x-content">
        <baseMessage @on-success="getBaseMessage"></baseMessage>
            <el-row style="margin-bottom: 60px;" v-if="alterationExamineOpinionList">
                <el-col :span="24" class="x-title">市中心意见</el-col>

                <el-row>
                    <el-col :span="24" class="x-subtitle" style="margin-top:40px;">经办人审查意见</el-col>
                    <!-- <el-col :span="24" class="x-subtitle">{{checkInfojbr.unit}}</el-col> -->
                    <el-col :span="24" class="x-textarea">
                        <el-input type="textarea" v-model="checkInfojbr.opinion" :rows="8" style="width:70%" disabled></el-input>
                    </el-col>
                    <el-col :span="24">
                        <el-form label-width="90px" :inline="true">
                            <el-form-item label="审查人">
                                <el-image style="width: 120px; height: 60px" :src="`${$config.baseUrlImg}${checkInfojbr.signature}`"></el-image>
                            </el-form-item>
                            <el-form-item label="审查日期" prop="createTime" >
                                <el-date-picker readonly v-model="checkInfojbr.createTime" value-format="yyyy-MM-dd"></el-date-picker>
                            </el-form-item>
                            <el-form-item label="审查状态" prop="status">
                                <el-select disabled v-model="checkInfojbr.status" placeholder="请选择">
                                    <el-option label="同意" :value="0"></el-option>
                                    <el-option label="拒绝" :value="1"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-form>
                    </el-col>
                </el-row>

            <el-row>
                <el-col :span="24" class="x-subtitle" style="margin-top:40px;">复核人审查意见</el-col>
                <el-col :span="24">
                    <el-form :inline="true" label-position="left" ref="checkInfo"  :rules="checkInfo" label-width="80px">
                        <el-form-item label="审查意见" prop="opinion" style="width: 100%;margin-right:60px;" class="x-textarea">
                            <el-input :readonly="disabled" type="textarea" v-model="checkInfo.opinion" :rows="8" style="width:400%"></el-input>
                        </el-form-item>
                        <el-form-item label="审查人" style="margin-right:60px;">
                            <el-image style="width: 120px; height: 60px" :src="`${$config.baseUrlImg}${checkInfo.signedPhoto || userInfo.signedPhoto}`"></el-image>
                        </el-form-item>
                        <el-form-item label="审查日期" prop="createTime" >
                            <el-date-picker :readonly="disabled" v-model="checkInfo.createTime" value-format="yyyy-MM-dd"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="审查状态" prop="status">
                            <el-select :disabled="disabled" v-model="checkInfo.status" placeholder="请选择">
                                <el-option label="同意" :value="0"></el-option>
                                <el-option label="拒绝" :value="1"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-form>
                </el-col>
            </el-row>

        </el-row>

        <div class="btn">
            <el-button v-if="!disabled" type="primary" @click="submitOpinion">提交</el-button>
            <el-button v-if="!disabled" @click="cancelInfo">取消</el-button>
            <el-button v-if="disabled" @click="back">返回</el-button>
        </div>
    </div>
</template>

<script>
    import Vue from 'vue'
    import { mapState } from 'vuex'
    import baseMessage from '../../components/baseMessage'
    import {submitAlterationExamineOpinion,getAlterationExamineOpinionList,getOpinionByAlterationIdAndEnumCode} from '@/api/project1/designChange/countyApply/index'
    // import config from "@/config/index.js";
    // import moment from "moment";
    // import {
    //   getInvAndCon,
    //   getAdvice,
    //   addAdvice,
    //   getSignature
    // } from "@/api/plannDesignBudget/reviewOpinions.js";
    export default {
        name: "countyBureauBaseMsg",
        components: {
            baseMessage,
        },
        data() {
            return {
                alterationRecordVO: null,
                checkInfo:{
                    projectId:localStorage.getItem("projectId"),
                    alterationId:'',   // 变更记录id
                    signature:'',      // 签字，创建人签名图片路径
                    status:0,
                    createTime:'',
                    opinion:'',
                    code:'DESIGN_CHANGE_INFORMATION_CITY_CENTER_1',
                    flowCode:'DESIGN_CHANGE_INFORMATION_CITY_CENTER_1',
                },
                checkInfojbr:{
                    projectId:localStorage.getItem("projectId"),
                    alterationId:'',   // 变更记录id
                    signature:'',      // 签字，创建人签名图片路径
                    status:0,
                    createTime:'',
                    opinion:'',
                },
                alterationExamineOpinionList:[],
                disabled:true,
            };
        },
        computed: {
            ...mapState({
                userInfo: (state) => state.user.userInfo
            }),
        },
        created() {
            if (this.$route.name === localStorage.getItem("key")) {
            this.disabled = false;
            }
            this.getTime()
        },
        methods: {
            getTime(){
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                if (month < 10) {
                    month = "0" + month;
                }
                if (day < 10) {
                    day = "0" + day;
                }
                var trueTime = year + "-" + month +"-" + day

                this.checkInfo.createTime = trueTime
            },
            // 获取审查的基本信息
            getBaseMessage(alterationRecordVO) {
                this.alterationRecordVO = alterationRecordVO;
                this.checkInfo.signature=this.userInfo.signedPhoto;
                this.checkInfo.alterationId =alterationRecordVO.id;
                this.checkInfo.projectId =alterationRecordVO.projectId;
                this.getCountCenterOpionion()
                this.getCountCenterOpionion1()
            },
            // 获取经办人审查意见
            getCountCenterOpionion() {
                let param = {
                    alterationId: this.checkInfo.alterationId,
                    code:"DESIGN_CHANGE_INFORMATION_CITY_CENTER_0"
                };
                getOpinionByAlterationIdAndEnumCode(param).then(res => {
                    if(res.data){
                        console.log(res,"经办人审查意见")
                        this.checkInfojbr.createTime = res.data.createTime.slice(0,10)
                        this.checkInfojbr.signature = res.data.signature
                        this.checkInfojbr.opinion = res.data.opinion
                        this.checkInfojbr.status = res.data.status
                        this.checkInfojbr.alterationId = res.data.alterationId
                    }
                });
            },
            // 获取经办人审查意见
            getCountCenterOpionion1() {
                let param = {
                    alterationId: this.checkInfo.alterationId,
                    code:"DESIGN_CHANGE_INFORMATION_CITY_CENTER_1"
                };
                getOpinionByAlterationIdAndEnumCode(param).then(res => {
                    if(res.data){
                        console.log(res,"复核人审查意见")
                        this.checkInfo.createTime = res.data.createTime.slice(0,10)
                        this.checkInfo.signature = res.data.signature
                        this.checkInfo.opinion = res.data.opinion
                        this.checkInfo.status = res.data.status
                        this.checkInfo.alterationId = res.data.alterationId
                    }
                });
            },
            // 提交复核审查意见
            submitOpinion(){
                const loading = this.$loading({
                    lock: true,
                    text: "Loading",
                    spinner: "el-icon-loading",
                    background: "rgba(0, 0, 0, 0.7)"
                });
                this.checkInfo["createTime"] = this.checkInfo["createTime"] + " " + "00:00:00"
                submitAlterationExamineOpinion(this.checkInfo).then(res => {
                    loading.close()
                    this.$message({
                        message: "提交成功",
                        type: "success"
                    });
                    this.$router.push("/projectManagement/projectImplementation/dealwith")
                }).catch(err=>{
                    loading.close()
                });
            },

            // 取消
            cancelInfo() {
                this.checkInfo.createTime = '';
                this.checkInfo.status = 0;
                this.checkInfo.opinion = '';
            },
            back(){
                this.$router.push("/projectManagement/projectImplementation/dealwith")
            },
        },
    };
</script>

<style scoped lang="scss">
    .x-content {
        margin-top: 20px;
        background-color: #fff;
        padding: 20px;
    .x-title {
        font-size: 18px;
        font-family: PingFang SC;
        font-weight: bold;
        line-height: 25px;
        color: rgba(77, 77, 77, 1);
        margin-bottom: 30px;
    }
    .x-project {
        display: flex;
        align-items: center;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        color: rgba(102, 102, 102, 1);
        margin-bottom: 20px;
    ul {
        display: flex;
    li {
        margin-right: 30px;
        font-size: 13px;
        font-family: PingFang SC;
        font-weight: 500;
        color: rgba(166, 166, 166, 1);
    }
    }
    }
    .x-other {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        line-height: 20px;
        color: rgba(102, 102, 102, 1);
        margin-bottom: 20px;
    ul {
        display: flex;
    li {
        margin-right: 60px;
    span {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        line-height: 20px;
        color: rgba(166, 166, 166, 1);
    }
    }
    }
    }
    .x-scale {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        line-height: 20px;

        color: rgba(166, 166, 166, 1);
        margin-bottom: 20px;
    }
    .x-scale ul li {
        padding: 5px 0;
    }
    .x-scale span:nth-of-type(1) {
        display: inline-block;
        width: 54%;
        text-align: right;
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        line-height: 20px;
        color: rgba(102, 102, 102, 1);
    }
    .x-total {
    span:first-child {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: bold;
        line-height: 20px;
        color: rgba(51, 51, 51, 1);
    }
    span:last-child {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        line-height: 20px;
        color: rgba(51, 51, 51, 1);
    }
    }
    .x-subtitle {
        font-size: 14px;
        font-family: PingFang SC;
        font-weight: 500;
        line-height: 20px;
        color: rgba(102, 102, 102, 1);
        margin-bottom: 10px;
    }
    .x-textarea {
        margin-bottom: 20px;
    }
    }
</style>